import java.awt.CardLayout;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import java.awt.Font;
import java.awt.Color;
import java.awt.SystemColor;

public class MatchScehdule {

	private JTextField txtSuwonVsSeoul;
	private JTextField textField;
	private JTextField txtSeoulVsBusan;
	private JTextField textField_2;
	private JTextField txtSuwonVsBusan;
	private JTextField textField_3;
	private JPanel matchPanel;
	private JButton btnTicketing;
	private JButton btnTicketing1;
	private JButton btnTicketing2;
	public MainPanel mp = new MainPanel();
	public static int i = 0;
	int activate;

	public MatchScehdule() {

		matchPanel = new JPanel();
		matchPanel.setLayout(new GridLayout(3, 1));

		txtSuwonVsSeoul = new JTextField();
		txtSuwonVsSeoul.setBackground(new Color(153, 102, 255));
		txtSuwonVsSeoul.setFont(new Font("Stencil Std", Font.PLAIN, 15));

		txtSuwonVsSeoul.setEditable(false);
		txtSuwonVsSeoul.setHorizontalAlignment(SwingConstants.CENTER);
		txtSuwonVsSeoul.setText("Suwon vs Seoul\r\n");
		matchPanel.add(txtSuwonVsSeoul);
		txtSuwonVsSeoul.setColumns(10);

		txtSeoulVsBusan = new JTextField();
		txtSeoulVsBusan.setBackground(new Color(153, 102, 255));
		txtSeoulVsBusan.setFont(new Font("Stencil Std", Font.PLAIN, 15));

		txtSeoulVsBusan.setEditable(false);
		txtSeoulVsBusan.setHorizontalAlignment(SwingConstants.CENTER);
		txtSeoulVsBusan.setText("Busan vs Pohang\r\n");
		matchPanel.add(txtSeoulVsBusan);
		txtSeoulVsBusan.setColumns(10);

		txtSuwonVsBusan = new JTextField();
		txtSuwonVsBusan.setBackground(new Color(153, 102, 255));
		txtSuwonVsBusan.setFont(new Font("Stencil Std", Font.PLAIN, 15));
		txtSuwonVsBusan.setEditable(false);
		txtSuwonVsBusan.setHorizontalAlignment(SwingConstants.CENTER);
		txtSuwonVsBusan.setText("Suwon vs Busan");
		matchPanel.add(txtSuwonVsBusan);
		txtSuwonVsBusan.setColumns(10);

		textField = new JTextField();
		textField.setBackground(new Color(153, 102, 255));
		textField.setEditable(false);
		textField.setHorizontalAlignment(SwingConstants.CENTER);
		textField.setText("12/14    12:00");
		textField.setFont(new Font("Stencil Std", Font.PLAIN, 12));
		matchPanel.add(textField);
		textField.setColumns(10);

		textField_2 = new JTextField();
		textField_2.setBackground(new Color(153, 102, 255));
		textField_2.setEditable(false);
		textField_2.setHorizontalAlignment(SwingConstants.CENTER);
		textField_2.setText("12/16    15:00");
		textField_2.setFont(new Font("Stencil Std", Font.PLAIN, 12));
		matchPanel.add(textField_2);
		textField_2.setColumns(10);

		textField_3 = new JTextField();
		textField_3.setBackground(new Color(153, 102, 255));
		textField_3.setEditable(false);
		textField_3.setHorizontalAlignment(SwingConstants.CENTER);
		textField_3.setText("12/18    13:00");
		textField_3.setFont(new Font("Stencil Std", Font.PLAIN, 12));
		matchPanel.add(textField_3);
		textField_3.setColumns(10);

		btnTicketing = new JButton("Ticket");
		btnTicketing.setBackground(SystemColor.inactiveCaption);
		btnTicketing.setFont(new Font("Minion Pro", Font.PLAIN, 17));
		matchPanel.add(btnTicketing);

		btnTicketing1 = new JButton("Ticket");
		btnTicketing1.setBackground(SystemColor.inactiveCaption);
		btnTicketing1.setFont(new Font("Minion Pro", Font.PLAIN, 17));
		matchPanel.add(btnTicketing1);

		btnTicketing2 = new JButton("Ticket");
		btnTicketing2.setBackground(SystemColor.inactiveCaption);
		btnTicketing2.setFont(new Font("Minion Pro", Font.PLAIN, 17));
		matchPanel.add(btnTicketing2);

		//show the first match in Suwon
		btnTicketing.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				try {
					FileReader currentIDReader = new FileReader("currentID.txt");
					BufferedReader currentMatchBufferedReader = new BufferedReader(
							currentIDReader);

					String line = null;
					if ((line = currentMatchBufferedReader.readLine()) != null) {

						mp.cardLayoutTicket.show(mp.cardTicketPanel, "");
						mp.matchcombo.setSelectedIndex(0);
					} // if user didn't login it give error
					else {
						JOptionPane.showMessageDialog(matchPanel,
								"LOGIN FIRST", "Error!",
								JOptionPane.ERROR_MESSAGE);
					}
				} catch (IOException e1) {

				}

			}
		});

		//show the second match in Seoul
		btnTicketing1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					FileReader currentIDReader = new FileReader("currentID.txt");
					BufferedReader currentMatchBufferedReader = new BufferedReader(
							currentIDReader);

					String line = null;
					if ((line = currentMatchBufferedReader.readLine()) != null) {
						mp.cardLayoutTicket.show(mp.cardTicketPanel, "");
						mp.matchcombo.setSelectedIndex(1);
					} else {
						JOptionPane.showMessageDialog(matchPanel,
								"LOGIN FIRST", "Error!",
								JOptionPane.ERROR_MESSAGE);
					}
				} catch (IOException e1) {

				}

			}
		});

		//show the third match in Busan
		btnTicketing2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					FileReader currentIDReader = new FileReader("currentID.txt");
					BufferedReader currentMatchBufferedReader = new BufferedReader(
							currentIDReader);

					String line = null;
					if ((line = currentMatchBufferedReader.readLine()) != null) {

						mp.cardLayoutTicket.show(mp.cardTicketPanel, "");
						mp.matchcombo.setSelectedIndex(2);
					} else {

						JOptionPane.showMessageDialog(matchPanel,
								"LOGIN FIRST", "Error!",
								JOptionPane.ERROR_MESSAGE);
					}
				} catch (IOException e1) {

				}

			}
		});
	}

	public JPanel matchschehdule() {
		return matchPanel;

	}

}
